package com.controller;

import com.model.ForderModel;
import com.services.IOrderServices;
import com.services.impl.OrderServicesImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Program: exam
 * @ClassName: ReFlightServletController
 * @Description: 处理退款请求
 * @Author: li
 * @Create: 2024-12-23 19:00
 */
@WebServlet("/ReFlightServlet")
public class ReFlightServletController extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("application/json;charset=utf-8");
        
        try {
            String oid = request.getParameter("oid");
            String fid = request.getParameter("fid");

            ForderModel forderModel = new ForderModel();
            forderModel.setFid(Integer.parseInt(fid));
            forderModel.setOid(Integer.parseInt(oid));
            
            IOrderServices services = new OrderServicesImpl();
            services.successOrder(forderModel);

            // Return success code
            response.getWriter().print("{\"code\":0}");
        } catch (Exception e) {
            // Return error code
            response.getWriter().print("{\"code\":1,\"msg\":\"退款操作失败\"}");
        }
    }
}
